<?php include './include/conf.php';

// On recupere les parametres passes par post
$nom = (isset($_POST['nom'])) ? $_POST['nom'] : NULL;
$prenom = (isset($_POST['prenom'])) ? $_POST['prenom'] : NULL;
$mdp = (isset($_POST['mdp'])) ? $_POST['mdp'] : NULL;
$newmdp = (isset($_POST['newmdp'])) ? $_POST['newmdp'] : NULL;
$adresse = (isset($_POST['adresse'])) ? $_POST['adresse'] : NULL;
$telfixe = (isset($_POST['tel_fixe'])) ? $_POST['tel_fixe'] : NULL;
$telport = (isset($_POST['tel_port'])) ? $_POST['tel_port'] : NULL;
$email = (isset($_POST['email'])) ? $_POST['email'] : NULL;

$chkAdr = (isset($_POST['chkAdr'])) ? $_POST['chkAdr'] : NULL;
$chktf = (isset($_POST['chktf'])) ? $_POST['chktf'] : NULL;
$chktp = (isset($_POST['chktp'])) ? $_POST['chktp'] : NULL;
$chkemail = (isset($_POST['chkemail'])) ? $_POST['chkemail'] : NULL;

/*
// Id de l adherent
$select_id = $pdo->prepare("select id_adherent as id from adherent where adherent.nom='$nom' and adherent.prenom='$prenom'");
$select_id->execute();
$id_adherent = $select_id->fetch()->id;

// ID de l adresse
$select_id = $pdo->prepare("select id_champ as id from champ where anonymat.id_adherent ='$id_adherent'");
$select_id->execute();
$id_adresse = $select_id->fetch()->id;

$update = $pdo->prepare("update anonymat SET anonymat.visible ='$chkAdr' where anonymat.id_adherent ='$id_adherent' and anonymat.id_champ ='$id_adresse'");
$update->execute();*/

// On verifie que le mot de passe rentre est correct
$select = $pdo->prepare("select * from adherent where mdp = ? and nom = '$nom' and prenom = '$prenom'");
$select->execute(array(crypt("$mdp","$prenom"."$nom")));

if($select->rowCount() == 1) // Si il y a 0 ligne le mot de passe entre est incorrect
{
	// Mise a jour des informations
	$update = $pdo->prepare("update adherent SET adherent.adresse='$adresse', adherent.tel_fixe='$telfixe', adherent.tel_port='$telport', adherent.email='$email' WHERE adherent.nom='$nom' and adherent.prenom='$prenom'");
	$update->execute();
	
	// Mise a jour du mot de passe
	$update = $pdo->prepare("update adherent set mdp = ? where nom = '$nom' and prenom = '$prenom'");
	$update->execute(array(crypt("$newmdp","$prenom"."$nom")));
}

?>